﻿
function $(id) { return document.getElementById ? document.getElementById(id) : null; }
function $name(id, _tagname) { return $(id).getElementsByTagName(_tagname) }

function LoadMapListData(pagesize) {
    if (typeof (mymap1) == "undefined") {
        return;
    }
    var x, y, str;    
    for (var i = 1; i <= pagesize; i++) {
        var OneData = $("_mapData_" + i);        
        if (!OneData || OneData.innerHTML.length < 5) {

            if ($("_ShowMap_" + i)) {
                $("_ShowMap_" + i).style.display = "none";
            }
            mymap1.AddData(0, 0, ""); 
            continue;
        }
        if (OneData.innerHTML.indexOf(",") > 0) {            
            str = OneData.innerHTML.split(",");
            x = str[0];
            y = str[1];
            if (x.length > 1 && y.length > 1 && $("Template" + i)) {
                var strMarker = $("Template" + i).innerHTML;               
                mymap1.AddData(x, y, strMarker);
            }
            else {
                if ($("_ShowMap_" + i)) {
                    $("_ShowMap_" + i).style.display = "none";
                }
            }
        }
        else {
            if ($("_ShowMap_" + i)) {
                $("_ShowMap_" + i).style.display = "none";
            }
        }
    }
    mymap1.Skin = 1; 
    mymap1.SetMap(); 
    mymap1.AutoZoom();
}

function pop(dealerIndex, pageNum) {
    if (typeof (mymap1) == "undefined") {
        return;
    }    
    if ($("ViewMapType") && $("ViewMapType").style.visibility == "hidden")
        OpenMap();
    if (document.documentElement.scrollTop) {
        if (document.documentElement.scrollTop > 220) document.documentElement.scrollTop = 220;
    }
    else {
        if (document.body.scrollTop > 220) document.body.scrollTop = 220;
    }
    var dealer_Index = parseInt(dealerIndex) - 1 + (parseInt(pageNum) - 1) * 10;

    mymap1.pop(dealer_Index);
}


/**************IndexCity************************/

function LoadMapDataNoTool(page_num) {   
    var mymap = new BitSoftMap("map" + page_num);
    mymap.LoadMap();
 
    var i = page_num;
    var OnePageData = $name("MapTable" + page_num, "th");
    var x, y, str;
    //mapObj.setCenter(new GLatLng(36.94, 106.08), 4);
    for (var i = 4; i < 15; i++) {
        if (!OnePageData[i])
            break;
        str = OnePageData[i].firstChild.innerHTML.split(",");
        OnePageData[i].parentNode.onclick = function() { var _index = this.getElementsByTagName("em")[0].innerHTML; var pagenum, page_all = $("pages").getElementsByTagName("a"); for (var _in_i = 0; _in_i < page_all.length; _in_i++) { if (page_all[_in_i].className == "current") { pagenum = (_in_i + 1); break; } }; pop(_index, pagenum) };
        x = str[0];
        y = str[1];
        var strMarker = $("Template" + (10 * (page_num - 1) + i - 3)).innerHTML;
        mymap.AddData(x, y, strMarker);

    }   
    mymap.Skin = 1;
    mymap.SetMap();
    mymap.AutoZoom();
}
/****************************************************/

function SetViewType(type) {
    writecookie("ViewMapType", type, 360000);
    if (type == "2") {
        CloseMap();
    }
    else {
        OpenMap();
    }
}
function SetViewTypeNoCookie(type) {
    if (type == "2") {
        CloseMap();
    }
    else {
        OpenMap();
    }
}
function GetViewType() {
    var oldcookie = readcookie("ViewMapType");
    if (oldcookie == "1") {
        OpenMap();
    }
    else {
        CloseMap();
    }
}


function OpenMap() {
    $("ViewMapTypeli1").className = "current";
    $("ViewMapTypeli2").className = "";
    $("ViewMapType").style.height = '';
    $("ViewMapType").style.visibility = "visible";    
}
function CloseMap() {
    $("ViewMapTypeli1").className = "";
    $("ViewMapTypeli2").className = "current";
    $("ViewMapType").style.height = '0'
    $("ViewMapType").style.visibility = "hidden";    
}


function readcookie(name) {
    var cookieValue = "";
    var search = name + "=";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            cookieValue = unescape(document.cookie.substring(offset, end))
        }
    }
    return cookieValue;
}

function writecookie(name, value, hours) {
    var expire = "";
    if (hours != null) {
        expire = new Date((new Date()).getTime() + hours * 3600000);
        expire = "; _domain=" + document.domain + "; expires=" + expire.toGMTString();
    }
    document.cookie = name + "=" + escape(value) + expire;
}